function demo() {
    var data = "{\"adr\": \"详细地址a\",\"tenant_num_id\": 6,\"town_num_id\": \"\",\"city_area_num_id\": 110101,\"client_list\": [\t{\t\t\"cont_empe\": \"联系人1\",\t\t\"telephone\": \"18201919191\",\t\t\"postcode\": \"22\",\t\t\"cont_empe_fax\": \"3\",\t\t\"cont_empe_mail\": \"4\",\t\t\"index\": 0\t}],\"collect_num_id\": \"\",\"loc_list\": [\t\"aaa\",\t\"ccccc\",\t\"bbbbb\"],\"sub_unit_name\": \"门店名称1\",\"type_num_id\": \"3\"\n}";
    $('#content').val(data)
}
//注意 转换的结果放哪里
// const $jsonTextArea = $(".jsonformatter-textarea");
function convert(sort=1) {
    try {
        var value = jsonsort(JSON.parse($('#content').val()), sort);
        $jsonTextArea.val(JSON.stringify(value, null, "\t"));
        $('#content').val(JSON.stringify(JSON.parse($('#content').val()), null, "\t"))
    } catch (e) {
        console["log"]["log"]("error：" + e);
        layer.msg(e["message"], function() {});
        return false
    }
}

function jsonsort(jsonData, sort) {
    var type = Object["prototype"]["toString"].call(jsonData);
    console["log"](Object["prototype"]["toString"].call(jsonData) + "-" + JSON.stringify(jsonData));
    let obj = {};
    if (type === "[object Object]") {
        let value = [];
        for (var item in jsonData) {
            value.push(item)
        };
        value.sort();
        if (sort != 1) {
            value.reverse()
        };
        for (var item in value) {
            item = value[item];
            var tt = jsonData[item];
            obj[item] = jsonsort(tt, sort)
        };
        return obj
    } else {
        if (type === "[object Array]") {
            let arr = [];
            var type = Object["prototype"]["toString"].call(jsonData[0]);
            if (type === "[object Array]" || type === "[object Number]") {
                jsonData["sort"]();
                if (sort != 1) {
                    jsonData["reverse"]()
                };
                return jsonData
            } else {
                for (var i = 0; i < jsonData.length; i++) {
                    arr.push(jsonsort(jsonData[i], sort))
                };
                return arr
            }
        } else {
            obj = jsonData;
            return obj
        }
    }
}